package com.pzh.assignment.common.bean.vo;

import com.pzh.assignment.common.bean.GlobalConstant;
import com.pzh.assignment.entity.Role;
import lombok.Data;

import java.time.format.DateTimeFormatter;


@Data
public class RoleVO {

    private Integer id;

    private String name;

    private String alias;

    private Integer weight;

    private String createTime;

    private String updateTime;


    public static RoleVO valueOf(Role role) {
        RoleVO vo = new RoleVO();
        vo.setId(role.getId());
        vo.setName(role.getName());
        vo.setAlias(role.getAlias());
        vo.setWeight(role.getWeight());
        if (role.getCreateTime() != null) {
            vo.setCreateTime(role.getCreateTime().format(DateTimeFormatter.ofPattern(GlobalConstant.DATE_FORMAT_PATTERN)));
        }
        if (role.getUpdateTime() != null) {
            vo.setUpdateTime(role.getUpdateTime().format(DateTimeFormatter.ofPattern(GlobalConstant.DATE_FORMAT_PATTERN)));
        }
        return vo;
    }
}
